PageInfo.register({
    "type": "Obj",
    "info": function () {

        var PageObj = {};

        PageObj.require = {
            "$": "jquery",
            "layui": "layui",
            "api": "/assets/js/components/common/data-api",
            "util": "/assets/js/components/common/common-util"
        };

        PageObj.page = function () {

            var FunUtil = {};
            var HtmUtil = {};
            var Page = {};

            HtmUtil.table = function (data) {
                var buf = [];

                for (var i = 0, len = data.length; i < len; i++) {

                    var obj   = data[i];
					var iscan = (String.HasText(obj.isValid) && obj.isValid == 1 );


                    buf.push('<tr>                                                                                                       ');
                    buf.push('    <td>' + obj.userName + '</td>                                                                                          ');
                    buf.push('    <td>'+(new Date(obj.serverCreateDate).Format("yyyy-MM-dd hh:mm:ss"))+'</td>                                                                                          ');
					buf.push('    <td>'+(new Date(obj.serverUpdateDate).Format("yyyy-MM-dd hh:mm:ss"))+'</td>                                                                                                  ');
                    buf.push('    <td>' + obj.userEmail + '</td>                                                                               ');
                    buf.push('    <td>' + obj.userTelephone + '</td>                                                                                   ');
                    buf.push('    <td>' +(iscan ? "启用" : "禁用" )  + '</td>                                                                                          ');
                    buf.push('    <td>                                                                                                   ');
                    buf.push('        <button class="layui-btn layui-btn-small admin-index-btn-edit '+(iscan ? "": "layui-btn-disabled")+'" data-id="'+obj.id+'">编辑</button>                       ');
                    buf.push('        <button class="layui-btn layui-btn-normal layui-btn-small admin-index-btn-del  '+(iscan ? "": "layui-btn-disabled")+'" data-id="'+obj.id+'">删除</button>       ');
                    buf.push('        <button class="layui-btn layui-btn-warm layui-btn-small admin-index-btn-update  '+(iscan ? "": "layui-btn-disabled")+'" data-id="'+obj.id+'">重置密码</button>      ');
                    buf.push('        <button class="layui-btn layui-btn-danger layui-btn-small admin-index-btn-forbid  " data-id="'+obj.id+'"  data-isValid="'+((String.HasText(obj.isValid) && obj.isValid == 1 ) ? "2" : "1") +'">'+((String.HasText(obj.isValid) && obj.isValid == 1 ) ? "禁用" : "启用" )+'</button>    ');
                    buf.push('    </td>                                                                                                  ');
                    buf.push('</tr>                                                                                                      ');
                }
                ;
                return buf.join("");


            };
            HtmUtil.add = function (data) {
                var buf = [];
                buf.push('<div id="admin-index-add">                                                                                                              ');
                buf.push('    <form class="layui-form" action="">                                                                                                 ');
                buf.push('        <div class="layui-form-item">                                                                                                   ');
                buf.push('            <label class="layui-form-label">姓名</label>                                                                                ');
                buf.push('            <div class="layui-input-block">                                                                                             ');
                buf.push('                <input type="text" name="userName" lay-verify="required" autocomplete="off" placeholder="" class="layui-input">     ');
                buf.push('            </div>                                                                                                                      ');
                buf.push('        </div>                                                                                                                          ');
                buf.push('        <div class="layui-form-item">                                                                                                   ');
                buf.push('            <label class="layui-form-label">账号</label>                                                                                ');
                buf.push('            <div class="layui-input-block">                                                                                             ');
                buf.push('                <input type="text" name="userTelephone" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">   ');
                buf.push('            </div>                                                                                                                      ');
                buf.push('        </div>                                                                                                                          ');
                buf.push('                                                                                                                                        ');
                buf.push('        <div class="layui-form-item">                                                                                                   ');
                buf.push('            <label class="layui-form-label">性别</label>                                                                                ');
                buf.push('            <div class="layui-input-block">                                                                                             ');
                buf.push('                 <input type="radio" name="userSex" value="1" title="男" checked="">                                                       ');
                buf.push('                 <input type="radio" name="userSex" value="2" title="女">                                                                  ');
                buf.push('            </div>                                                                                                                      ');
                buf.push('        </div>                                                                                                                          ');
                buf.push('                                                                                                                                        ');
                buf.push('        <div class="layui-form-item">                                                                                                   ');
                buf.push('            <label class="layui-form-label">电话</label>                                                                                ');
                buf.push('            <div class="layui-input-block">                                                                                             ');
                buf.push('                <input type="text" name="userTelephone" lay-verify="required|phone|number" placeholder="请输入" autocomplete="off" class="layui-input">   ');
                buf.push('            </div>                                                                                                                      ');
                buf.push('        </div>                                                                                                                          ');
                buf.push('                                                                                                                                        ');
                buf.push('        <div class="layui-form-item">                                                                                                   ');
                buf.push('            <label class="layui-form-label">邮箱</label>                                                                                ');
                buf.push('            <div class="layui-input-block">                                                                                             ');
                buf.push('                <input type="text" name="userEmail" lay-verify="required|email" placeholder="请输入" autocomplete="off" class="layui-input">   ');
                buf.push('            </div>                                                                                                                      ');
                buf.push('        </div>                                                                                                                          ');
                buf.push('                                                                                                                                        ');
                buf.push('        <div class="layui-form-item">                                                                                                   ');
                buf.push('            <div class="layui-input-block">                                                                                             ');
                buf.push('                <button class="layui-btn" lay-submit="" lay-filter="admin-index-add-btn">确定</button>                                            ');
                buf.push('            </div>                                                                                                                      ');
                buf.push('        </div>                                                                                                                          ');
                buf.push('    </form>                                                                                                                             ');
                buf.push('</div>                                                                                                                                  ');
                return buf.join("");
            };
            HtmUtil.update = function (data) {

                console.log(data);
                var obj = data.data;
                var buf = [];
                buf.push('<div id="admin-index-add">                                                                                                              ');
                buf.push('    <form class="layui-form" action="">                                                                                                 ');
                buf.push('        <div class="layui-form-item">                                                                                                   ');
                buf.push('            <label class="layui-form-label">姓名</label>                                                                                ');
                buf.push('            <div class="layui-input-block">                                                                                             ');
                buf.push('                <input type="text" name="userName"  lay-verify="required" autocomplete="off" placeholder="" class="layui-input" value="'+obj.userName+'">     ');
                buf.push('            </div>                                                                                                                      ');
                buf.push('        </div>                                                                                                                          ');
                buf.push('        <div class="layui-form-item">                                                                                                   ');
                buf.push('            <label class="layui-form-label">账号</label>                                                                                ');
                buf.push('            <div class="layui-input-block">                                                                                             ');
                buf.push('                <input type="text" name="userTelephone" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" value="'+obj.userTelephone+'" >   ');
                buf.push('            </div>                                                                                                                      ');
                buf.push('        </div>                                                                                                                          ');
                buf.push('                                                                                                                                        ');
                buf.push('        <div class="layui-form-item">                                                                                                   ');
                buf.push('            <label class="layui-form-label">性别</label>                                                                                ');
                buf.push('            <div class="layui-input-block">                                                                                             ');
                buf.push('                 <input type="radio" name="userSex" value="1" title="男" checked="">                                                       ');
                buf.push('                 <input type="radio" name="userSex" value="2" title="女">                                                                  ');
                buf.push('            </div>                                                                                                                      ');
                buf.push('        </div>                                                                                                                          ');
                buf.push('                                                                                                                                        ');
                buf.push('        <div class="layui-form-item">                                                                                                   ');
                buf.push('            <label class="layui-form-label">电话</label>                                                                                ');
                buf.push('            <div class="layui-input-block">                                                                                             ');
                buf.push('                <input type="text" name="userTelephone"  lay-verify="required|phone|number" placeholder="请输入" autocomplete="off" class="layui-input" value="'+obj.userTelephone+'">   ');
                buf.push('            </div>                                                                                                                      ');
                buf.push('        </div>                                                                                                                          ');
                buf.push('                                                                                                                                        ');
                buf.push('        <div class="layui-form-item">                                                                                                   ');
                buf.push('            <label class="layui-form-label">邮箱</label>                                                                                ');
                buf.push('            <div class="layui-input-block">                                                                                             ');
                buf.push('                <input type="text" name="userEmail" lay-verify="required|email" placeholder="请输入" autocomplete="off" class="layui-input" value="'+obj.userEmail+'">   ');
                buf.push('            </div>                                                                                                                      ');
                buf.push('        </div>                                                                                                                          ');

                buf.push('        <div class="layui-form-item" style="display:none">                                                                                                   ');
                buf.push('            <label class="layui-form-label">id</label>                                                                                ');
                buf.push('            <div class="layui-input-block">                                                                                             ');
                buf.push('                <input type="text" name="id" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" value="'+obj.id+'">   ');
                buf.push('            </div>                                                                                                                      ');
                buf.push('        </div>                                                                                                                          ');



                buf.push('                                                                                                                                        ');
                buf.push('        <div class="layui-form-item">                                                                                                   ');
                buf.push('            <div class="layui-input-block">                                                                                             ');
                buf.push('                <button class="layui-btn" lay-submit="" lay-filter="admin-index-update-btn">确定</button>                                            ');
                buf.push('            </div>                                                                                                                      ');
                buf.push('        </div>                                                                                                                          ');
                buf.push('    </form>                                                                                                                             ');
                buf.push('</div>                                                                                                                                  ');
                return buf.join("");
            };


            Page.show = function () {

                var request = this.api;
                var util = this.util;
				
				
				util.filter();

                console.log(util)
                var $query = $("#admin-index-query-btn");

                var Help = {

                    data: {
                        tableData:[],
                        activityRow:{},
                        totalPage:0,
                        isStart:false,
                        form:{
                            "pageNo": 1,
                            "pageSize": 5,
                        }
                    },

                    fun4start: function () {
                        var $this = this;
                        //addUser
util.layout(function(cparam){
                        $("#admin-index-add-user-btn").unbind("click").bind("click", function () {
                        	
                        	if($("#admin-index-add").length > 0) return;
                        	
                            layer.open({ type: 1, content: HtmUtil.add(""), area: ['480px', '378px'],  skin: 'layui-layer-demo', success: function (layero, index) {
                                    util.layout(function(cparam){
                                        cparam.form.on('submit(admin-index-add-btn)', function (data) {
                                            console.log(data);
                                            request.ntqSysUser.add(data.field, function (cdata) {
                                                layer.close(index);
												
                                            })
                                            return false;
                                        });
                                    })
                                }
                            });
                        });
						
						cparam.form.on('submit(admin-index-query-btn)', function (data) {
                            request.ntqSysUser.query(Object.assign($this.data.form, data.field), function (cdata) {


                                $this.data.totalPage = cdata.totalPage;
                               
                                if($this.data.form.pageNo == 1) $this.fun4page(cdata);

                            })
                            return false;
                        });
                        
                        setTimeout(function(){
                        	$query.click();
                        },2000);
					});	 
 
                    },

                    fun4search: function () {
                        var $this = this;
						
						console.log("===============");
						

                        util.layout(function(cparam){

                            
							
							 
                        });
						
						
                    },
                    fun4page:function(data){
                        var $this = this;
                        util.layout(function(cparam){
                            cparam.laypage({cont: 'admin-index-body-page' ,curr:$this.data.form.pageNo, pages: $this.data.totalPage , skip: true,jump: function (obj, first) {
                                $this.data.form.pageNo = obj.curr;
                                if(String.HasText(data)){ $this.fun4table(data);data = ""; return;}

                                request.ntqSysUser.query($this.data.form, function (cdata) {
                                     $this.fun4table(cdata);
                                 });

                                return false;
                            }});
                        });


                    },

                    fun4table: function (cdata) {
                        var $table = $("#admin-index-table");
                        var $this = this;


                        $table.html(HtmUtil.table(cdata.results));
                        console.log(cdata);

                        $("button.admin-index-btn-edit").unbind("click").bind("click", function () {
							
                            var $self = this;
                            var id    = $self.getAttribute("data-id");
							 
							if($self.getAttribute("class").indexOf("layui-btn-disabled") > 0) return;

                            request.ntqSysUser.get({"id":id}, function (cdata) {
                                layer.open({  type: 1,   content: HtmUtil.update(cdata),  area: ['480px', '378px'], skin: 'layui-layer-demo',  success: function (layero, index) {
                                    util.layout(function(cparam){

                                        cparam.form.on('submit(admin-index-update-btn)', function (data) {
                                            console.log(data);
                                            request.ntqSysUser.update(data.field, function (cdata) {
                                                layer.close(index);
                                                console.log(cdata);
												
												$query.click();
                                            });
                                            return false;
                                        });
                                    });
                                }
                                });

                            });
                        });


                        $("button.admin-index-btn-del").unbind("click").bind("click", function () {
                            var $self = this;
                            var id = $self.getAttribute("data-id");
							if($self.getAttribute("class").indexOf("layui-btn-disabled") > 0) return;
							
							layer.confirm('确定操作？', {btn: ['确定','取消'] }, function(){
								
								request.ntqSysUser.delete({"id":id}, function (cdata) {
							    	$query.click();
									layer.closeAll();
                                });

							}, function(){ });
 
                        });
						
						$("button.admin-index-btn-update").unbind("click").bind("click", function () {
                            var $self = this;
                            var id = $self.getAttribute("data-id");
							if($self.getAttribute("class").indexOf("layui-btn-disabled") > 0) return;
							
							
								
							layer.confirm('确定操作？', {btn: ['确定','取消'] }, function(){
								
								request.ntqSysUser.reset({"id":id}, function (cdata) {
							    	$query.click();
									layer.closeAll();
									layer.msg('重置密码为：ntq123456');
                                });

							}, function(){ });
 
                        });


                        $("button.admin-index-btn-forbid").unbind("click").bind("click", function () {
                            var $self = this;
                            var id = $self.getAttribute("data-id");
                            var isValid = $self.getAttribute("data-isValid");
							if($self.getAttribute("class").indexOf("layui-btn-disabled") > 0) return;
							
							layer.confirm('确定操作？', {btn: ['确定','取消'] }, function(){
								
								request.ntqSysUser.change({"id":id,"isValid":isValid}, function (cdata) {
							    	$query.click();
									layer.closeAll();
                                });

							}, function(){ });
							 
                        });

                    },


                };
                Help.fun4start();


            };

            return Page;

        };

        return PageObj;
    }
});